#pragma once
#include <string>
#include "Reference.hpp"

class Canvas;
class Renderer;
typedef struct GLFWwindow GLFWwindow;
class FrameGLFW : public Reference
{
public:
    FrameGLFW();
    ~FrameGLFW();

    static void Initialize();

    static void Destory();

    bool initWindow(int x, int y, int w, int h);

    void run();

protected:

    void clean();

    ///////////////////////////////////////////////////////////////////////////
    // callback functions
    ///////////////////////////////////////////////////////////////////////////

    void resize(int w, int h);
    void close();
    void mouse(int button, int action, int mods);
    void cursor(double xpos, double ypos);
    void scroll(double xoffset, double yoffset);
    void keyboard(int key, int scancode, int action, int mods);
    void drop(int count, const char** paths);

    ///////////////////////////////////////////////////////////////////////////
    // static callback functions
    ///////////////////////////////////////////////////////////////////////////

    static void Error(int errCode, const char* errMsg);
    static void Resize(GLFWwindow*, int w, int h);
    static void Close(GLFWwindow*);
    static void Mouse(GLFWwindow*, int button, int action, int mods);
    static void Cursor(GLFWwindow*, double xpos, double ypos);
    static void Scroll(GLFWwindow*, double xoffset, double yoffset);
    static void Keyboard(GLFWwindow*, int key, int scancode, int action, int mods);
    static void Drop(GLFWwindow*, int count, const char** paths);

    static bool _initialized;

    std::string _title;
    GLFWwindow* _wnd = nullptr;

    ref_ptr<Canvas>   _canvas;   // draw board
    ref_ptr<Renderer> _renderer; // renderer
};

